/**
 * 防抖函数通用实现
 * @param callbackFn 回调函数
 * @param delay N 毫秒内执行一次
 * @param immediate 是否立即执行
 */
export const getDebounceCallbackFn = (callbackFn: (...args: any) => any, delay: number, immediate = false): () => void => {
    // 防抖定时器
    let timer: NodeJS.Timeout;
    return (...args: any) => {
        if (immediate) {
            callbackFn.apply(this, args);
            immediate = false;
            return;
        }
        clearTimeout(timer);
        timer = setTimeout(() => {
            callbackFn.apply(this, args);
        }, delay);
    };
};
